package com.sleep.ruledemo.service.imol;

import com.sleep.ruledemo.service.TestFuncService;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * @author GuoAo
 * @className TestFuncerviceImpl
 * @date 2025/3/26
 * @description TODO 策略模式的map简化结构
 */
@Service
public class TestFuncServiceImpl implements TestFuncService {

    private final Map<String, Function<String,String>> funcMap = new HashMap<>();

    @PostConstruct
    public void init(){
        funcMap.put("phone",this::getPhoneValue);
        funcMap.put("id",this::getIdValue);
    }

    @Override
    public String HandlerValue(String params) {
        return funcMap.get(params).apply(params);
    }

    public String getPhoneValue(String params){
        return "phone";
    }

    public String getIdValue(String params){
        return "id";
    }
}
